﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.Core
{
    public static class EnumHelper
    {
        // cannot make an extension method because I need to call the type, not an instance
        public static T ParseEnum<T>(string value) where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum)
                throw new ArgumentException("T must be an enumerated type");

            if (string.IsNullOrEmpty(value))
                return default(T);

            foreach (T t in Enum.GetValues(typeof(T)))
            {
                if (t.ToString().ToLower().Equals(value.Trim().ToLower()))
                    return t;
            }

            return default(T);
        }
    }
}
